﻿
#include "EasyTcpServer.h"

/// 用 select 模型建立的 Server

const unsigned short SERVER_PORT = 4444;


int main(int argc, const char* argv[])
{
    EasyTcpServer server;
    int nret = 0;

#if 0
    CTextMessage txtMsg;
    txtMsg.parse((DataHead*)_recvBuff);
    const char* content = txtMsg.getString();
#endif

    MessageBuildHelper mbh;
    TextMessage* tMsg = mbh.buildTextMessage("你好啊啊啊啊啊啊！");
    std::string hohoho;
    mbh.parseTextMessage((DataHead*)tMsg, hohoho);
    mbh.freeResource(tMsg);

    do
    {
        EasyTcpServer::loadSocket();

        server.initSocket();
        
        server.bind("0.0.0.0", SERVER_PORT);

        server.listen();

        while (server.isRunning())
        {
            server.onRun();
        }

    } while (0);

    server.close();    
    EasyTcpServer::unloadSocket();

    myprintf("程序退出...\n");
    getchar();
    return 0;
}